#! /usr/bin/perl
use strict;
my %dep;
my $pos = 1;
sub inspect;
sub inspect {
  return if defined $dep{my $f = shift};
  $dep{$f} = $pos++;
  open my $FILE, "<$f"
    or die "could not open $f\n";;
  (/^((include)|(require)) (\S+)/ and inspect $4)
    while <$FILE>;
  close $FILE;
}
inspect $_ for @ARGV;
print join(" ", sort { $dep{$a} <=> $dep{$b} } keys %dep), "\n";
